//
//  HLFriendsListRequest.m
//  YueYue
//
//  Created by hulu001 on 2023/5/19.
//

#import "HLFriendsListRequest.h"

@implementation HLFriendsListRequest
{
    HLFriendType _type;
}

- (instancetype)initWithType:(HLFriendType)type
{
    self = [super init];
    if (self){
        _type = type;
        self.page = 1;
    }
    return self;
}

- (NSString *)requestUrl
{
    return @"/relationship/friend_list";
}

- (YTKRequestMethod)requestMethod
{
    return YTKRequestMethodGET;
}

- (id)requestArgument
{
    return @{@"pageNum":@(self.page),
             @"type":@(_type),
             @"pageSize":HLListPageSize};
}

- (NSArray <HLFriendsModel *> *)friendsList
{
    NSArray *lists = @[];
    NSDictionary *data = [self.result valueForKey:@"data"];
    if (![data isKindOfClass:[NSDictionary class]]){
        return lists;
    }
    
    NSArray *records = [data valueForKey:@"records"];
    if (records.count > 0) {
        HLFriendType type = _type;
        [HLFriendsModel mj_setupNewValueFromOldValue:^id(id object, id oldValue, MJProperty *property) {
            if ([property.name isEqualToString:@"type"]){
                return @(type);
            }
            return oldValue;
        }];
       lists = [HLFriendsModel mj_objectArrayWithKeyValuesArray:records];
    }
    
    return lists;
}


@end
